package com.etone.smartAudit.controller;

import com.etone.eos.controller.AbstractEosController;
import com.etone.eos.domain.*;
import com.etone.smartAudit.service.EosService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/***
 * 区块链调用controller
 */
@Api(value = "EOS调用controller", tags = "EOS调用controller")
@RestController
public class EOSController extends AbstractEosController {

    @Autowired
    private EosService eosService;


    @ApiOperation(value = "添加文件MD5进入合约", tags = "EOS调用controller")
    @ResponseBody
    @PostMapping("/eos/addFile")
    @Override
    public MD5FileVO addFileToAction(@RequestBody CreateParamDTO createParam) {
        return eosService.addFile(createParam);
    }

    @ApiOperation(value = "根据合约hash主键获取存储的信息", tags = "EOS调用controller")
    @ResponseBody
    @GetMapping("/eos/{id}")
    @Override
    public MD5FileVO getTable(@ApiParam("合约主键id") @PathVariable String actionId) {
        return eosService.getFile(actionId);
    }

    @ApiOperation(value = "根据交易主键获取合约存储的信", tags = "EOS调用controller")
    @ResponseBody
    @GetMapping("/eos/trx/{trxId}")
    @Override
    public MD5FileVO getTransactionDetail(String trxId) {
        TransactionDetail transactionDetail = eosService.getTransactionDetail(trxId);
        MD5FileVO dataBeanX = transactionDetail.getTraces().get(0).getAct().getData();
        return dataBeanX;
    }

}
